<template>
  <el-container>
    <div class="header">
      <div class="title">苏小课直播教学平台</div>
      <div class="user-info">
        <div class="notification">
          <i class="bell-icon">🔔</i>
          <span class="badge">1</span>
        </div>
        <div class="user">您好，{{ userStore.uname }}！</div>
        <div class="actions">
          <a href="#">修改密码</a> |
          <a href="./login.html">退出</a>
        </div>
      </div>
    </div>

    <el-header>
      <div class="breadcrumb-nav">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item @click='navigateTo("teacherHome/home.html")'>首页</el-breadcrumb-item>
          <el-breadcrumb-item>我的班级</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </el-header>

    <el-main>
      <div class="content-wrapper">
        <el-form :inline="true" class="filter-form">
          <el-form-item label="时间">
            <el-date-picker
              v-model="filter.startDate"
              type="date"
              placeholder="开始时间"
            />
            <span>至</span>
            <el-date-picker
              v-model="filter.endDate"
              type="date"
              placeholder="结束时间"
            />
          </el-form-item>
          <el-form-item>
            <el-input v-model="filter.className" placeholder="请输入班级名称" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="filterClasses">搜索</el-button>
          </el-form-item>
        </el-form>
        <div class="class-cards">
          <div
            class="class-card"
            v-for="classItem in filteredClasses"
            :key="classItem.id"
            @click="navigateTo('classDetail/classDetail.html')"
          >
            <div>{{ classItem.name }}</div>
            <div>入学时间：{{ classItem.startDate }}</div>
            <div>毕业时间：{{ classItem.endDate }}</div>
            <div>学生：{{ classItem.studentCount }}人</div>
          </div>
        </div>
      </div>
    </el-main>
  </el-container>
</template>

<script setup>
import { useUserStore } from "../../store/user.js";
let userStore = useUserStore();
userStore.storeInit();

import { ref, computed } from "vue";
import "element-plus/dist/index.css";
import "../../../public/header.css";
import {
  ElContainer,
  ElHeader,
  ElMain,
  ElBreadcrumb,
  ElBreadcrumbItem,
  ElForm,
  ElFormItem,
  ElDatePicker,
  ElInput,
  ElButton,
  ElImage,
} from "element-plus";

const filter = ref({
  startDate: "",
  endDate: "",
  className: "",
});

const classes = ref([
  {
    id: 1,
    name: "20级会计1班",
    startDate: "2020-09-20",
    endDate: "2021-07-10",
    studentCount: 40,
  },
  {
    id: 2,
    name: "20级会计2班",
    startDate: "2020-09-20",
    endDate: "2021-07-10",
    studentCount: 40,
  },
  {
    id: 3,
    name: "19级会计1班",
    startDate: "2020-09-20",
    endDate: "2021-07-10",
    studentCount: 40,
  },
]);

function navigateTo(page) {
  window.location.href = `/src/pages/${page}`;
}

const filteredClasses = computed(() => {
  return classes.value.filter((classItem) => {
    const matchName =
      !filter.value.className ||
      classItem.name.includes(filter.value.className);
    const matchStartDate =
      !filter.value.startDate ||
      new Date(classItem.startDate) >= new Date(filter.value.startDate);
    const matchEndDate =
      !filter.value.endDate ||
      new Date(classItem.endDate) <= new Date(filter.value.endDate);
    return matchName && matchStartDate && matchEndDate;
  });
});

const filterClasses = () => {
  // This function can have additional filtering logic if necessary
};

const viewClassDetail = (id) => {
  // Navigate to the class detail page
  alert(`Viewing details for class ID: ${id}`);
};
</script>

<style scoped>
#app {
  font-family: Arial, sans-serif;
  background-color: #f5f5f5;
  padding: 20px;
}

.el-header {
  background-color: #fff;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.top-nav {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.breadcrumb-nav {
  padding: 0 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: #fff;
  border-bottom: 1px solid #ddd;
}

.header .title {
  font-size: 24px;
  color: #1e90ff;
}

.header .user-info {
  display: flex;
  align-items: center;
}

.header .user-info .notification {
  margin-right: 20px;
  position: relative;
}

.header .user-info .notification .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: red;
  color: #fff;
  border-radius: 50%;
  padding: 2px 5px;
  font-size: 12px;
}

.header .user-info .user {
  margin-right: 10px;
  color: #333;
}

.header .user-info .actions a {
  margin: 0 5px;
  color: #1e90ff;
  text-decoration: none;
}

.el-main {
  display: flex;
  justify-content: center;
}

.content-wrapper {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.filter-form {
  display: flex;
  justify-content: center; /* Centering the form horizontally */
  align-items: center;
  margin-bottom: 20px;
  width: 100%; /* Ensuring form takes the full width */
}

.filter-form .el-form-item {
  margin-right: 20px;
}

.class-cards {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.class-card {
  background-color: #fff;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  width: 200px;
  text-align: center;
}

.class-card:hover {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  border-color: #1e90ff;
}
</style>
